<template>
  <div class="goods-item" @click="itemClick">
      <!-- <img :src="showImage" alt=""> -->
      <!-- 懒加载 -->
      <img v-lazy="showImage" alt="">
      <div class="goods-info">
            <p>{{good.title}}</p>
            <span class="price">{{good.price}}</span>
            <span class="collect">{{good.cfav}}</span>
      </div>
  </div>
</template>

<script>
export default {
    props: {
        good:{
            type:Object,
            default(){
                return {}
            }
        }
    },
    computed: {
      showImage(){
        return this.good.image||this.good.show.img
      }
    },
    methods: {
         getImgUrl(url){
            return "~"+url;
        },
        itemClick(){
          // console.log("跳转详情页");
          this.$router.push('/detail/'+this.good.iid)
          // 带参数
          // this.$router.push({
          //   path:'/detail',
          //   query:{id:1}
          //   })
        }
    } 
}
</script>

<style>
.goods-item{
  width: 48%;
  padding-bottom: 40px;
  position: relative;
}
.goods-item img{
  width: 100%;
}
.goods-info{
    position: absolute;
    font-size: 12px;
    bottom: 5px;
    left: 0;
    right: 0;
    text-align: center;
    overflow: hidden;
}
.goods-info p{
    overflow: hidden;
    text-overflow:ellipsis; 
    white-space: nowrap; /* 只显示一行 */
    margin-bottom: 3px;
}
.goods-info .price {
    color: var(--color-high-text);
    margin-right: 20px;
  }
.goods-info .collect {
    position: relative;
  }
.goods-info .collect::before{
    content: '';
    position: absolute;
    left: -15px;
    top: -1px;
    width: 14px;
    height: 14px;
    color: red;
    background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
}
</style>